#ifndef CURVE_H_
#define CURVE_H_

#include <string>
#include <vector>
#include "vmath/vmath.h"
#include "mesh.h"

namespace goatgfx {

class Curve {
private:
	std::string name;

	std::vector<Vector3> cv;
	float thickness;

	int segm_subdiv, ring_subdiv;

	/// normalized arc-lengths of each control vertex from the beginning
	mutable std::vector<float> length;
	mutable bool lengths_valid;

	mutable Vector3 bbmin, bbmax;
	mutable bool bbox_valid;

	mutable Mesh mesh;
	mutable bool mesh_valid;

	float reparametrize(float t) const;

	void calc_cvlengths() const;
	void update_mesh() const;

public:
	Curve();
	Curve(const Vector3 *points, int num_points);
	Curve(const Vector2 *points, int num_points);

	void set_name(const char *name);
	const char *get_name() const;

	bool empty() const;

	void set_thickness(float thickness);
	void set_subdiv(int seg, int ring);

	void clear();
	void add_point(const Vector3 &pt);
	Vector3 &get_point(int idx);
	const Vector3 &get_point(int idx) const;
	int get_count() const;

	Vector3 &operator[] (int idx);
	const Vector3 &operator[] (int idx) const;

	void get_bbox(Vector3 *bbmin, Vector3 *bbmax) const;
	void normalize();

	Vector3 get_pos(float t) const;
	Vector3 operator() (float t) const;

	void draw() const;
};

}	// namespace goatgfx

#endif	// CURVE_H_
